export default {
	data (){
		return {
			// value4: '',//搜索框
            loading: false,//表单懒加载
        	formValidate: {//表单
                name: '',
                date: '',
                content: '',
                star: 2.5,
                blogsid: '',//表单的隐藏域用于文章的id
                id:''//判断是修改还是添加
            },
            data6: [//动态获取请求到的数据
            ],
            pageData: {
                total:20,
                limit: 10,
                page: 1,
                pages: 2,
                name:''
            },
            select: []

		}
	},
	methods: {
		reload (item) {//得到数据对页面的重新载入
	        if (this.formValidate.blogsid) {
                this.$http({
                    method:"POST",
                    url:`http://localhost:3000/${ this.module }/listtoo`+this.formValidate.blogsid,
                    data:this.pageData
                })
                .then((response) => {
                    console.log(response);
                    this.data6 = response.data;
                    this.pageData.total = response.data.length;
                })
                .catch((response) => {
                    console.log('出错')
                });
            } else {
                this.$http({
                    method:"POST",
                    url:`http://localhost:3000/${ this.module }/list`,
                    data:this.pageData
                })
                .then((response) => {
                    console.log(response);
                    this.data6 = response.data.rows;
                    this.pageData.total = response.data.total;
                })
                .catch((response) => {});
               
            }
	    },
		formDataCreate (){//表单提交新数据
            var data = this.formValidate;
            // delete data.id;
            console.log(this.$route.query.id)
            // this.formValidate.star = this.valueStar;
            console.log(data)
           this.$http({
                method:"POST",
                url:`http://localhost:3000/${ this.module }/data`,
                data:this.formValidate
            })
            .then((response) => {
                this.reload();
            })
            .catch((response) => {
                console.log(response)
            });
        },
        formDataUpdate (that_id){//表单修改
            console.log(this.formValidate);
            this.$http({
                method:"POST",
                url:`http://localhost:3000/${ this.module }/data`+that_id,
                data:this.formValidate
            })
            .then((response) => {
                this.$Message.success('修改成功!');
                this.reload();
            })
            .catch((response) => {
                console.log(response)
            });
        },
        remove (index,id) {
            if (this.select == 0 ) {
                this.data6.splice(index, 1);
                this.$http({
                    method:"DELETE",
                    url:`http://localhost:3000/${ this.module }/data`+id,
                        // data:this.formValidate
                })
                .then((response) => {
                    this.reload();
                })
                .catch((response) => {
                    console.log(response)
                });
            }
            else {
                this.warning();
                var idBox = [];
                for (var i = 0; i < this.select.length; i++) {
                    idBox.push(this.select[i]._id);
                }
                console.log(idBox);
                this.$http({
                    method:"DELETE",
                    url:`http://localhost:3000/${ this.module }/data`+idBox,
                        // data:this.formValidate
                })
                .then((response) => {
                    console.log('成功')
                    this.reload();
                })
                .catch((response) => {
                    console.log(response)
                });
            }

        },
        search () {//搜索
            // alert(this.value4)
            // this.reload(this.value4);
       		this.reload();
        },
        changePage(page){//分页方法
            this.loading = true;
            var that = this;
            var tableTimer = setTimeout(function() {
                that.loading = false;
            }, 600);

            this.$http({
                method:'POST',
                url:`http://localhost:3000/${ this.module }/list`,
                data:{
                    page:page,
                }
            }).then((response)=>{
                this.data6 = response.data.rows;
            })
        },
        changePageSize(limit) {//一页最大数据数码
            this.loading = true;
            var that = this;
            var tableTimer = setTimeout(function() {
                that.loading = false
            }, 600);
            this.$http({
                method:'POST',
                url:`http://localhost:3000/${ this.module }/list`,
                data:{
                    rows:limit
                }
            }).then((response)=>{
                this.data6 = response.data.rows;
            })
        },


	},
    created: function() {//钩子函数创建
        this.formValidate.blogsid = this.$route.query.id;        
        this.reload();
    }

}